package com.ricky.onlineShop.controller.trading;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ricky.common.utils.poi.ExcelUtil;
import com.ricky.onlineShop.read.trading.service.TradingPerformanceReadService;
import com.ricky.onlineShop.serviceBus.trading.TradingPerformanceServiceBus;
import com.ricky.onlineShop.shop.trading.pojo.TradingPerformance;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ricky.common.annotation.Log;
import com.ricky.common.core.controller.BaseController;
import com.ricky.common.core.domain.AjaxResult;
import com.ricky.common.enums.BusinessType;
import com.ricky.common.core.page.TableDataInfo;

/**
 * 绩效Controller
 *
 * @author ricky
 * @date 2024-07-17
 */
@RestController
@RequestMapping("/onlineShop/performance")
public class TradingPerformanceController extends BaseController {
    @Autowired
    private TradingPerformanceServiceBus tradingPerformanceServiceBus;

    /**
     * 查询绩效列表
     */
    @GetMapping("/myPerformance")
    public AjaxResult myPerformance()
    {
        startPage();
        Map<String, Object> map = tradingPerformanceServiceBus.myPerformance();
        return AjaxResult.success(map);
    }

    @PreAuthorize("@ss.hasPermi('onlineShop:performance:list')")
    @GetMapping("/list")
    public TableDataInfo list(TradingPerformance tradingPerformance)
    {
        startPage();
        List<TradingPerformance> list = tradingPerformanceServiceBus.selectTradingPerformanceList(tradingPerformance);
        return getDataTable(list);
    }

    /**
     * 导出绩效列表
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:performance:export')")
    @Log(title = "绩效", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TradingPerformance tradingPerformance)
    {
        List<TradingPerformance> list = tradingPerformanceServiceBus.selectTradingPerformanceList(tradingPerformance);
        ExcelUtil<TradingPerformance> util = new ExcelUtil<TradingPerformance>(TradingPerformance.class);
        util.exportExcel(response, list, "绩效数据");
    }

    /**
     * 获取绩效详细信息
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:performance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tradingPerformanceServiceBus.selectTradingPerformanceById(id));
    }

    /**
     * 新增绩效
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:performance:add')")
    @Log(title = "绩效", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TradingPerformance tradingPerformance)
    {
        return toAjax(tradingPerformanceServiceBus.insertTradingPerformance(tradingPerformance));
    }

    /**
     * 修改绩效
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:performance:edit')")
    @Log(title = "绩效", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TradingPerformance tradingPerformance)
    {
        return toAjax(tradingPerformanceServiceBus.updateTradingPerformance(tradingPerformance));
    }

    /**
     * 删除绩效
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:performance:remove')")
    @Log(title = "绩效", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tradingPerformanceServiceBus.deleteTradingPerformanceByIds(ids));
    }
}
